package com.sailfish.springbootdemo.service.db1;

import org.springframework.stereotype.Service;

@Service
public class PcbaLineRelatedDeviceServiceImpl implements PcbaLineRelatedDeviceService {

    /*@Autowired
    private PcbaLineRelatedDeviceDao pcbaLineRelatedDeviceDao;

    @Autowired
    private PcbaLineDao pcbaLineDao;

    @Autowired
    private PcbaCompanyDao pcbaCompanyDao;

    @Autowired
    private PcbaWorkshopDao pcbaWorkshopDao;

    @Autowired
    private PcbaProcessDao pcbaProcessDao;

    @Qualifier("MysqlTransactionManager1")
    @Autowired
    private DataSourceTransactionManager transactionManager1;

    @Autowired
    private OperateService operateService;

    private String operateSmallType = "线体管理";

    @Override
    public List<PcbaLineRelatedDevice> getAllByLine(Integer pcbaLineId) {
        return pcbaLineRelatedDeviceDao.getAllByLine(pcbaLineId);
    }

    @Override
    public Result deleteByLineAndDevice(Integer pcbaLineId, Integer pcbaDeviceId) {
        try{
            if(pcbaLineId == null || "".equals(pcbaLineId.toString())){
                return ResultUtil.error(500, "缺少参数pcbaLineId", "Miss Param pcbaLineId", null);
            }
            if(pcbaDeviceId == null || "".equals(pcbaDeviceId.toString())){
                return ResultUtil.error(500, "缺少参数pcbaDeviceId", "Miss Param pcbaDeviceId", null);
            }

            String userId = UserHeaderHolder.getUserId();
            List<PcbaLineRelatedDevice> oldPcbaLineRelatedDeviceList = pcbaLineRelatedDeviceDao.getAllByLineAndDeviceResource(pcbaLineId, pcbaDeviceId);

            Integer integer = pcbaLineRelatedDeviceDao.deleteByLineAndDevice(pcbaLineId, pcbaDeviceId);
            if(integer > 0){

                // 操作日志
                operateService.addOperate(new Operate(1, Integer.parseInt(userId), operateSmallType, 2, 1, new Date(), JSONObject.toJSONString(oldPcbaLineRelatedDeviceList), null));

                return ResultUtil.success(null);
            }
            return ResultUtil.error(500, "操作失败", "Operate Fail", null);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @Transactional(transactionManager = "MysqlTransactionManager1")
    @Override
    public Result updatePcbaLineRelatedDeviceAndPcbaLine(PcbaLineRelatedDevice pcbaLineRelatedDeviceResource, String lastUpkeepTimeStr) {
        *//*try{
            PcbaLineRelatedDevice updatePcbaLineRelatedDeviceResource = new PcbaLineRelatedDevice();
            updatePcbaLineRelatedDeviceResource.setStatus(1);
            updatePcbaLineRelatedDeviceResource.setAge(pcbaLineRelatedDeviceResource.getAge());
            updatePcbaLineRelatedDeviceResource.setName(pcbaLineRelatedDeviceResource.getName());
            updatePcbaLineRelatedDeviceResource.setPurpose(pcbaLineRelatedDeviceResource.getPurpose());
            updatePcbaLineRelatedDeviceResource.setAssetNumber(pcbaLineRelatedDeviceResource.getAssetNumber());
            *//**//*SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            Date date = format.parse(lastUpkeepTimeStr);
            updatePcbaLineRelatedDeviceResource.setLastUpkeepTime(date);*//**//*
            updatePcbaLineRelatedDeviceResource.setUpdateTime(new Date());
            updatePcbaLineRelatedDeviceResource.setPcbaLineRelatedDeviceResourceId(pcbaLineRelatedDeviceResource.getPcbaLineRelatedDeviceResourceId());

            int aaaaa = pcbaLineRelatedDeviceResourceDao.updatePcbaLineRelatedDevice(updatePcbaLineRelatedDeviceResource);

            // 判断该线体下是否所有资产都完善，如果全部完善则修改 线体状态，否则不动，其他过保等逻辑后续补充
            List<PcbaLineRelatedDevice> allByLine = pcbaLineRelatedDeviceResourceDao.getAllByLine(pcbaLineRelatedDeviceResource.getPcbaLineId());
            Boolean b = true;
            for (int a=0;a<allByLine.size();a++){
                if(!allByLine.get(a).getPcbaLineRelatedDeviceResourceId().equals(pcbaLineRelatedDeviceResource.getPcbaLineRelatedDeviceResourceId())){
                    if(!"1".equals(allByLine.get(a).getStatus().toString())){
                        b = false;
                        break;
                    }
                }
            }
            if(b){
                PcbaLine updatePcbaLine = new PcbaLine();
                updatePcbaLine.setUpdateTime(new Date());
                updatePcbaLine.setStatus(1);
                updatePcbaLine.setPcbaLineId(pcbaLineRelatedDeviceResource.getPcbaLineId());

                pcbaLineDao.updatePcbaLine(updatePcbaLine);
            }
            return ResultUtil.success(null);
        }catch (Exception e){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }*//*
        return ResultUtil.success(null);
    }

    @Override
    public PcbaLineRelatedDevice getPcbaLineRelatedDeviceById(Integer pcbaLineRelatedDeviceId) {
        return pcbaLineRelatedDeviceDao.getPcbaLineRelatedDeviceById(pcbaLineRelatedDeviceId);
    }

    @Override
    public List<PcbaLineRelatedDevice> getPcbaLineRelatedDeviceFilledAssetNumber(String searchValue) {
        *//*List<PcbaLineRelatedDevice> list = pcbaLineRelatedDeviceResourceDao.getPcbaLineRelatedDeviceResourceFilledAssetNumber(searchValue);
        for (PcbaLineRelatedDevice pcbaLineRelatedDeviceResource : list) {
            PcbaLine pcbaLine = pcbaLineDao.getPcbaLineById(pcbaLineRelatedDeviceResource.getPcbaLineId());
            if(pcbaLine != null){
                pcbaLine.setPcbaCompany(pcbaCompanyDao.getPcbaCompanyById(pcbaLine.getPcbaCompanyId()));
                pcbaLine.setPcbaWorkshop(pcbaWorkshopDao.getPcbaWorkshopById(pcbaLine.getPcbaWorkshopId()));
                pcbaLine.setPcbaProcess(pcbaProcessDao.getPcbaProcessById(pcbaLine.getPcbaProcessId()));
                pcbaLineRelatedDeviceResource.setPcbaLine(pcbaLine);
            }
        }
        return list;*//*
        return null;
    }*/
}
